package com.sharainy.contoller;

import com.alibaba.fastjson.JSONObject;
import com.sharainy.pojo.Account;
import com.sharainy.pojo.Merchant;
import com.sharainy.pojo.Settlement;
import com.sharainy.service.AccountService;
import com.sharainy.service.MerchantService;
import com.sharainy.service.SettlementService;
import com.sharainy.util.RestResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/settlement")
public class SettlementController {
    @Autowired
    private AccountService accountService;
    @Autowired
    private SettlementService settlementService;
    @Autowired
    private MerchantService merchantService;
    @RequestMapping(value = "/settlementPage")
    public String index(){
        return "settlement";
    }
    @RequestMapping("/settleDetail")
    @ResponseBody
    public RestResponse rechargeDetail(int merchantId){
        JSONObject jsonMain = new JSONObject();
        List<Account> accountList = accountService.selectEndAccount(merchantId+"");
        Settlement settlement = settlementService.selectNewSettlement(merchantId+"");
        Merchant merchant = merchantService.selectMerchantById(merchantId+"");
        String companyName = merchantService.selectCompanyName(merchant.getCompanyid());
        jsonMain.put("accountList",accountList);
        jsonMain.put("settlement",settlement);
        jsonMain.put("merchant",merchant);
        jsonMain.put("companyName",companyName);
        RestResponse restResponse = RestResponse.succuess();
        restResponse.setData(jsonMain);
        return restResponse;
    }
    @RequestMapping("/checkSettlePwd")
    @ResponseBody
    public RestResponse checkSettlePwd(String pwd, String merchantId){
        JSONObject jsonMain = new JSONObject();
        RestResponse restResponse=null;
        if ("123456".equals(pwd)){
            merchantService.settlementState(merchantId);
            restResponse = RestResponse.succuess();
        }else{
            restResponse = RestResponse.fail();

        }
        return restResponse;
    }
}
